package com.example.fresheveryday.controller;


import com.example.fresheveryday.po.User;
import com.example.fresheveryday.restful.JsonResult;
import com.example.fresheveryday.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ll
 * @since 2023-07-5
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/list")
    public List<User> list(){
        return userService.list();
    }
    @RequestMapping("saveorupdate")
    public JsonResult saveorupdate(@RequestBody User user){
        System.out.println("修改" + user);
        userService.saveOrUpdate(user);
        return JsonResult.success("success");
    }
    @RequestMapping("getbyid")
    public User getbyid(int id){
        System.out.println(userService.getById(id));
        return userService.getById(id);
    }
    @RequestMapping("del")
    public JsonResult del(String id){
        userService.removeById(id);
        return JsonResult.success("success");
    }
}
